{% extends "base_generic.html" %}

{% load widget_tweaks %}

{% block content %}
  <div class="card" style="max-width: 400px; margin: 50px auto;">
    <h1>用户登录</h1>
    {% if form.errors %}
      <p class="text-danger">您的用户名和密码不匹配，请再试一次。</p>
    {% endif %}

    {% if next %}
      {% if user.is_authenticated %}
        <p class="text-warning">您的账户无权访问此页面。请登录具有访问权限的账户。</p>
      {% else %}
        <p class="text-info">请登录以查看此页面。</p>
      {% endif %}
    {% endif %}

    <form method="post" action="{% url 'login' %}">
      {% csrf_token %}

      <div class="form-group">
        <label for="{{ form.username.id_for_label }}">用户名:</label>
        {{ form.username|add_class:"form-control" }}
      </div>
      <div class="form-group">
        <label for="{{ form.password.id_for_label }}">密码:</label>
        {{ form.password|add_class:"form-control" }}
      </div>

      <button type="submit" class="btn btn-primary btn-block">登录</button>
      <input type="hidden" name="next" value="{{ next }}" />
    </form>

    <p style="margin-top: 20px;"><a href="{% url 'password_reset' %}" class="text-muted">忘记密码？</a></p>
  </div>
{% endblock %}
